package com.wesley.netty.jvm;

import com.wesley.netty.clazz.TestClass;

/**
 * AllotOnStack
 * 粘上分配内存
 *
 * 如下参数不会发生GC
 * -Xmx15m -Xms15m -XX:+DoEscapeAnalysis -XX:+PrintGC -XX:+EliminateAllocations
 *
 * 关闭逃逸分析，开启标量替换 发生大量GC
 * -Xmx15m -Xms15m -XX:-DoEscapeAnalysis -XX:+PrintGC -XX:+EliminateAllocations
 * 开启逃逸分析，关闭标量替换 发生大量GC
 * -Xmx15m -Xms15m -XX:-DoEscapeAnalysis -XX:+PrintGC -XX:+EliminateAllocations
 * @author WangPanYong
 * @since 2021/06/10 16:10
 */
public class AllotOnStack {

    public static void main(String[] args) {
        long start = System.currentTimeMillis();
        for (int i = 0; i < 100000000; i++) {
            alloc();
        }
        long end = System.currentTimeMillis();
        System.out.println(end - start);
    }

    private static void alloc() {
        TestClass t = new TestClass();
        t.setId(666);
        t.setDesc("wesley");
    }
}
